package cn.itcast.pattern.proxy.jdk_proxy3;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandleInfo;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyInvocationH implements InvocationHandler {

    //被代理的对象
    public  Object target;
    public  void setTarget(Object target){
        this.target = target;
    }

    public Object getInstance(){
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), this.target.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return  method.invoke(target,args);
     }
}
